package conservare.modelo;

import java.io.Serializable;
import java.text.ParseException;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import conservare.modelo.servico.ServicoPrincipal;
import conservare.modelo.type.DiaSemana;
import conservare.util.DataUtil;

@Entity
@Table(name="TB_SERV_PRINC_AGENDA_SEMANAL")
public class ItemDeDiaSemana implements Serializable{

	private static final long serialVersionUID = -1057325393611141164L;

	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="AGENDA_SEMANAL_ID")
	private Integer id;
	
	@ManyToOne(targetEntity=ServicoPrincipal.class, fetch=FetchType.LAZY)
	@JoinColumn(name = "SERV_PRINC_ID", referencedColumnName = "SERV_PRINC_ID")
	private ServicoPrincipal servicoPrincipal;
	
	@Enumerated(EnumType.ORDINAL)
	@Column(name="DIA_SEMANA")
	private  DiaSemana diaSemana;
	
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="QTD_HORAS_DIA")
	private Date qtdHorasDia;
	
	
	public ItemDeDiaSemana(){}
	
	
	public ItemDeDiaSemana(DiaSemana diaSemana) {
		super();
		this.diaSemana = diaSemana;
	}


	public ItemDeDiaSemana(ServicoPrincipal servicoPrincipal, DiaSemana diaSemana, Date qtdHorasDia) {
		super();
		this.servicoPrincipal = servicoPrincipal;
		this.diaSemana = diaSemana;
		this.qtdHorasDia = qtdHorasDia;
	}

	public DiaSemana getDiaSemana() {
		return diaSemana;
	}


	public void setDiaSemana(DiaSemana diaSemana) {
		this.diaSemana = diaSemana;
	}

	public ServicoPrincipal getServicoPrincipal() {
		return servicoPrincipal;
	}

	
	public void setServicoPrincipal(ServicoPrincipal servicoPrincipal) {
		this.servicoPrincipal = servicoPrincipal;
	}


	public Date getQtdHorasDia() {
		return qtdHorasDia;
	}

	public void setQtdHorasDia(Date qtdHorasDia) {
		this.qtdHorasDia = qtdHorasDia;
	}


	public String getQtdHorasFormattedTime() {
		
		String dataFormatada = "";
        try {
        	dataFormatada =  DataUtil .getFormattedTime(getQtdHorasDia(), "HH:mm");
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
        return dataFormatada;
    }


	public Integer getId() {
		return id;
	}


	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((diaSemana == null) ? 0 : diaSemana.hashCode());
		result = prime
				* result
				+ ((servicoPrincipal == null) ? 0 : servicoPrincipal.hashCode());
		return result;
	}


	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ItemDeDiaSemana other = (ItemDeDiaSemana) obj;
		if (diaSemana != other.diaSemana)
			return false;
		if (servicoPrincipal == null) {
			if (other.servicoPrincipal != null)
				return false;
		} else if (!servicoPrincipal.equals(other.servicoPrincipal))
			return false;
		return true;
	}


	@Override
	public String toString() {
		return "ItemDeDiaSemana [servicoPrincipal=" + servicoPrincipal
				+ ", diaSemana=" + diaSemana + ", qtdHorasDia=" + qtdHorasDia
				+ "]";
	}

	
	
}
